﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace ImageProcessing
{
    public class Utilities
    {
        public static String getImageName(string imageURL)
        {
            String[] imageName = imageURL.Split('/');
            return imageName[imageName.Length - 1];
        }

        public static String getImageType(string imageURL)
        {
            String[] imageName = imageURL.Split('.');
            return imageName[imageName.Length - 1];
        }

        public static List<FileInfo> GetLastUpdatedFileInDirectory(DirectoryInfo directoryInfo)
        {
            FileInfo[] files = directoryInfo.GetFiles();
            List<FileInfo> lastUpdatedFile = new List<FileInfo>();
            DateTime lastUpdate = new DateTime();
            foreach (FileInfo file in files)
            {
                if (file.LastAccessTime > lastUpdate)
                {
                    lastUpdatedFile.Add(file);
                    lastUpdate = file.LastAccessTime;
                }
            }

            return lastUpdatedFile;
        }

    }
}